<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物料编号" prop="goodId">
        <el-input
          v-model="queryParams.goodId"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库位" prop="locationId">
        <el-input
          v-model="queryParams.locationId"
          placeholder="请输入库位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="托盘号" prop="ctl">
        <el-input
          v-model="queryParams.ctl"
          placeholder="请输入托盘号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="sts">
        <el-select
          v-model="queryParams.sts"
          placeholder="请选择明细状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.ck_sts"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

<!--      <el-form-item label="出库状态" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择出库状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.ck_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item label="创建时间" prop="addTimes">
        <el-date-picker
          clearable
          v-model="queryParams.addTimes"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期时间"
          end-placeholder="结束日期时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择创建时间范围">
        </el-date-picker>
      </el-form-item>
      <!--      <el-form-item label="" prop="UNIT">
              <el-input
                v-model="queryParams.UNIT"
                placeholder="请输入单位"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">刷新</el-button>
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:bak:add']"
            >新增
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:bak:edit']"
            >修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:bak:remove']"
            >删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:bak:export']"
            >导出
            </el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>-->
    <div class="chart-container">
      <div class="bar-container">
        <div class="bar" style="background-color: #faa5ac; height: 20px;"></div>
        <div class="label">未执行</div>
      </div>
      <div class="bar-container">
        <div class="bar" style="background-color: #ead6a3; height: 20px;"></div>
        <div class="label">堆垛机已写入</div>
      </div>
      <div class="bar-container">
        <div class="bar" style="background-color: #a9bfed; height: 20px;"></div>
        <div class="label">输送机已写入</div>
      </div>
      <div class="bar-container">
        <div class="bar" style="background-color: #a7dc83; height: 20px;"></div>
        <div class="label">堆垛机出库完成</div>
      </div>
    </div>

    <el-table v-loading="loading" border :data="bakList" :row-style="rowStyle" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="出库单号"  sortable align="center" prop="orderId"/>
      <el-table-column label="物料编号" sortable align="center" prop="goodId"/>
      <el-table-column label="物料名称" align="center" prop="goodName"/>
      <el-table-column label="库位号" sortable align="center" prop="locationId"/>
      <el-table-column label="托盘号" sortable align="center" prop="ctl"/>
      <el-table-column label="状态" align="center" prop="sts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ck_sts" :value="scope.row.sts"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="出库类型"  align="center" sortable prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ck_type" :value="scope.row.type"/>
        </template>
      </el-table-column>-->
      <el-table-column label="数量" sortable align="center" prop="goodsNum"/>
      <el-table-column label="出库时间" align="center" prop="addtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.addtime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="BUSINESSID">
          <el-input v-model="form.BUSINESSID" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="goodId">
          <el-input v-model="form.goodId" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="sts">
          <el-input v-model="form.sts" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="SPECIFICATION">
          <el-input v-model="form.SPECIFICATION" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="REMARK">
          <el-input v-model="form.REMARK" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="" prop="scaleUnit">
          <el-input v-model="form.scaleUnit" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="goodsTypeId">
          <el-input v-model="form.goodsTypeId" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="addtime">
          <el-date-picker clearable
                          v-model="form.addtime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="endtime">
          <el-date-picker clearable
                          v-model="form.endtime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="UNIT">
          <el-input v-model="form.UNIT" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="storageAreaId">
          <el-input v-model="form.storageAreaId" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="locationId">
          <el-input v-model="form.locationId" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="storageId">
          <el-input v-model="form.storageId" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="params">
          <el-input v-model="form.params" placeholder="请输入"/>
        </el-form-item>
        <el-form-item label="" prop="ctl">
          <el-input v-model="form.ctl" placeholder="请输入"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>
<style>
.chart-container {
  display: flex;
  align-items: center; /* 使所有条形图和标签垂直居中 */
  gap: 10px; /* 条形图之间的间隔 */
}

.bar-container {
  display: flex;
  flex-direction: column;
  align-items: center; /* 使条形图和标签水平居中 */
}

.bar {
  width: 50px; /* 假设条形图的宽度为50px */
  margin-bottom: 5px; /* 条形图和标签之间的间隔 */
}

.label {
  font-size: 14px; /* 标签的字体大小 */
  color: #333; /* 标签的文字颜色 */
}
</style>
<script>
import {listBak, getBak, delBak, addBak, updateBak} from "@/api/system/bak";

export default {
  dicts: ['ck_sts', 'kc_sts', 'ck_type'],
  name: "Bak",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      bakList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        addTimes:[],
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        BUSINESSID: null,
        goodId: null,
        goodName: null,
        sts: null,
        SPECIFICATION: null,
        goodsNum: null,
        SORTID: null,
        REMARK: null,
        WEITH: null,
        PRICE: null,
        scaleUnit: null,
        goodsTypeId: null,
        packingNum: null,
        addtime: null,
        endtime: null,
        totalVolume: null,
        GVOLUME: null,
        UNIT: null,
        storageAreaId: null,
        locationId: null,
        pickNum: null,
        trNum: null,
        xqType: null,
        buyNum: null,
        storageId: null,
        params: null,
        ctl: null,
        type: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          {required: true, message: "$comment不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    rowStyle({row, rowIndex}) {
      if (row.sts === "0") {
        return {backgroundColor: '#faa5ac'}; // 返回被点击行的样式
      }else if (row.sts === '1') {
        return {backgroundColor: '#ead6a3'};
      }else if (row.sts === '2') {
        return {backgroundColor: '#a9bfed'};
      }else if (row.sts === '10') {
        return {backgroundColor: '#a7dc83'};
      }
      return {}; // 返回其他行的默认样式
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listBak(this.queryParams).then(response => {
        this.bakList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单刷新
    reset() {
      this.form = {
        orderId: null,
        BUSINESSID: null,
        goodId: null,
        goodName: null,
        sts: null,
        SPECIFICATION: null,
        goodsNum: null,
        SORTID: null,
        REMARK: null,
        pageNum: null,
        WEITH: null,
        PRICE: null,
        scaleUnit: null,
        goodsTypeId: null,
        packingNum: null,
        addtime: null,
        endtime: null,
        totalVolume: null,
        GVOLUME: null,
        UNIT: null,
        storageAreaId: null,
        locationId: null,
        pickNum: null,
        trNum: null,
        xqType: null,
        buyNum: null,
        storageId: null,
        params: null,
        ctl: null,
        type: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 刷新按钮操作 */
    resetQuery() {
      this.queryParams.addTimes=[]
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getBak(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateBak(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBak(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + orderIds + '"的数据项？').then(function () {
        return delBak(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/bak/export', {
        ...this.queryParams
      }, `bak_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
